import QtQuick 2.15
import QtQuick.Window 2.15
import QtMultimedia 5.12
import QtQuick.Controls 2.15

Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("Hello World")

    Camera {                                    //程序启动自动开始拉流
        id: camera
        imageCapture {                          //属性（只读）
            onImageCaptured: {                  //imageCaptured信号的槽函数
                //信号imageCaptured(requestId,preview)中，preview以URL用于Image控件
                photoPreview.source = preview   // 将帧（preview）展示到Image控件上
            }
        }
    }

    VideoOutput {   //控件，展示来自Camera的流
        source: camera
        anchors.fill: parent
        anchors.rightMargin: parent.width*0.5
    }

    Image {
        id: photoPreview
        anchors.fill: parent
        anchors.leftMargin: parent.width*0.5
    }

    Button{
        text: "拍照"
        anchors.bottom: parent.bottom

        onClicked: {
            camera.imageCapture.capture();  // 自动发送imageCaptured信号给onImageCaptured
        }
    }
}
